
package com.idealighter.game.games.zjh.handler;

import com.idealighter.game.core.annotation.ResMsgHandler;
import com.idealighter.game.games.zjh.ZjhPlayer;
import com.idealighter.game.games.zjh.message.ResBetMsg;
import com.idealighter.game.message.ModuleMsgIdConstant;
import com.idealighter.game.message.core.ResMessage;
import com.idealighter.game.robot.core.Player;
import com.idealighter.game.robot.handler.ResMessageHandler;
import com.idealighter.utils.code.RandCodeUtil;

import java.util.concurrent.TimeUnit;


@ResMsgHandler(ModuleMsgIdConstant.Zjh.RES_BET)
public class ResBetHandler implements ResMessageHandler {
  // private static final Logger LOG =
  // LoggerFactory.getLogger(ResBetHandler.class);

  @Override
  public void action(Player player, ResMessage message) {
    ResBetMsg msg = (ResBetMsg) message;
    ZjhPlayer zjhPlayer = (ZjhPlayer) player;
    if (msg.getPlayerId() == player.playerId) {
      zjhPlayer.round++;
    }

    zjhPlayer.preBet = msg.getChips();
    zjhPlayer.preBetType = msg.getType();
    // 桌面上总下注
    zjhPlayer.totalBet = msg.getTotalBetChips();

    if (msg.getNextOptPlayerId() == zjhPlayer.playerId) {
      player.schedule(() -> {
        if (msg.getNextOptPlayerId() == player.playerId) {
          zjhPlayer.bet();
        }

      }, RandCodeUtil.random(1, 10), TimeUnit.SECONDS);
    }

  }
}
